/**  
* @Title: WechatInstalmentOrderServiceImpl.java
* @Package com.hjb.service.impl.Wechat
* @author <a href="mailto:125671254@qq.com">Pan Xinwen</a>panxinwen
* @date 2018年1月14日 下午3:31:45
* @version V1.0  
*/ 
package com.hjb.service.impl.Wechat;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hjb.service.Wechat.WechatInstalmentOrderService;
import com.hjb.service.domain.InstalmentOrder.InstalmentOrder;
import com.hjb.service.domain.InstalmentOrder.InstalmentOrderExample;
import com.hjb.service.mapper.InstalmentOrderMapper;
import com.hjb.service.mapper.SiteUserOrderMapper;

/**
* @ClassName: WechatInstalmentOrderServiceImpl
* @Description: TODO(执行还款计划)
* @author <a href="mailto:125671254@qq.com">Pan Xinwen</a>panxinwen
* @date 2018年1月14日 下午3:31:45
*/
@Service
public class WechatInstalmentOrderServiceImpl implements WechatInstalmentOrderService {
	
	private Logger log = LoggerFactory.getLogger(this.getClass()); 
	
	@Autowired
	private SiteUserOrderMapper siteUserOrderMapper;
	
	@Autowired
	private InstalmentOrderMapper instalmentOrderMapper;
	
	@Override
	public Map<String,Object> getInstalmentOrder(String orderId) {
		
		//获取租户正在执行的合同
//		SiteUserOrder record = new SiteUserOrder();
//		record.setStatus(5);
//		record.setTenancyMobile(phonenumber);
//		record = siteUserOrderMapper.selectOne(record);
//		
//		log.info("获取还款中的合同：phonenumber===="+phonenumber+"，record===="+JSON.toJSONString(record));
		
		//查询分期信息
		InstalmentOrderExample example = new InstalmentOrderExample();
		example.createCriteria().andOrderIdEqualTo(orderId);
		example.setOrderByClause("term_no");
		List<InstalmentOrder> list = instalmentOrderMapper.selectByExample(example);
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("present", "");
		map.put("list", list);
		list.stream().filter(instalmentOrder ->(instalmentOrder.getStatus().equals("3")||instalmentOrder.getStatus().equals("1"))).findFirst().ifPresent(ins ->map.put("present", ins));;
		
		//判断当前应还的期数
//		list.forEach(instalmentOrder ->{
//			
//			if(instalmentOrder.getStatus().equals("1")){
//				instalmentOrder.setStatus("4");//本期应还
//				break;
//			}
//			
//		});
		
		
		return map;
	}

	@Override
	public Object updateOrderStatus(String orderId,Integer status) {
		
		return null;
	}

}
